%macro get_itemized;

	/*
	Only thing we need is last year's state income tax deduction
	*/
	
	proc printto log = "&logdir/get_itemized.txt" new;
	run;
	
	proc sort data = rlib.filing_status(where=(prim_tin_x~=.)) out = unique nodupkey;
		by prim_tin_x;
	run;

	data _null_;
		set unique;
		file "&tmpdir/tinlist" dlm=',';
		put prim_tin_x;
	run;


	proc sql noprint;
		[connection details redacted]
			create table rlib.itemized as
			select * from connection to iq 
		(
		select distinct
			a.prim_tin_x,
			max(b.[redacted] - coalesce(b.[redacted],0) - coalesce(b.[redacted],0))
				as state_incm_tax_ded
		from #tinlist as a 
			inner join [redacted] as b 
				on(a.prim_tin_x = b.[redacted])
		where b.[redacted] = &base_yr - 1
		group by a.prim_tin_x
		order by a.prim_tin_x
	);
	disconnect from iq;
	quit;




	proc printto;
	run;

%mend;